package Testpackage;

import java.net.*;
import java.io.*;

class Server extends Thread{
	
	Socket verbindung = null;
	
	public Server(){
		init();
	}
	
	public static void main (String[]args){

		new Server();
	}
	
	public void init (){
		try {
			ServerSocket server = new ServerSocket(8080);
			while(true){
				System.out.println("Watet auf Anfrage");
				verbindung = server.accept();
				new Thread(this).start();
				}
		}catch (IOException e){
			System.out.println(e.toString());
		}
	}
	
	public synchronized void run(){
		System.out.println("Runmethode gestartet");
		try{
			
			BufferedReader in = new BufferedReader(new InputStreamReader(
					verbindung.getInputStream()));
			BufferedWriter out = new BufferedWriter(new OutputStreamWriter(
					verbindung.getOutputStream()));
			
			String s = in.readLine();
			
			System.out.println(s);
			
				if (s.equals("Test")){
					out.write("Getestet");
				}else{
					out.write(s);
				}

			out.newLine();
			out.flush();
			
			in.close();
			out.close();
			
			
		}catch(Exception e){
			System.out.println(e.toString());
		}
	}
}
